<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="600px, initial-scale=1.0" />
    <title>ChatGPT</title>
    <style>
      #aiarea {
        width: 96%;
        height: 150px;
        padding: 5px 10px;
        min-height: 40px;
        border: 2px solid aqua;
        border-bottom: none;
        margin: 0 2%;
        border-radius: 8px 8px 0 0;
        transition: all 0.3s;
        position: fixed;
        left: 0;
        bottom: 0;
        box-sizing: border-box;
        background: #fffa;
        font: 400 14px/18px Consolas;
      }
      button {
        outline: none;
      }
      #aiarea:focus {
        outline: 2px solid yellow;
      }
      .record {
        background: rgba(200, 250, 200, 0.3);
        border-radius: 6px;
        padding: 1px 6px;
        margin: 8px 6px;
        min-height: 24px;
        font: normal 16px/24px consolas;
        color: #222;
        white-space: pre-wrap;
        word-wrap: break-word;
      }
      .ans {
        background-color: #0ff4;
      }
      #tip {
        width: 80%;
        box-shadow: 1px 1px 8px 0px gray;
        top: -100px;
        position: fixed;
        margin: 0 10%;
        opacity: 0.8;
        background-color: #fffe;
        transition: top 0.4s;
        padding: 4px;
        z-index: 99999999;
        border-radius: 6px;
        padding: 5px 10px;
      }
      #tip.hide {
        top: -400px;
      }
      #tip.show {
        top: 20px;
      }
      div#record {
        margin: 0 2% 200px;
      }
      .chatbtn {
        position: fixed;
        bottom: 156px;
        border-radius: 6px;
        border: none;
        padding: 1px 3px;
        opacity: 0.8;
        background: #0ff6;
        margin-bottom: 2px;
        padding: 5px 10px;
        left: 2%;
        font: 600 15px/18px Consolas;
      }
      button:hover {
        opacity: 1;
      }
      #aiRes:before {
        content: "Residue: ";
      }
      #aiRes:after {
        content: "W";
      }
      #switch-pin-btn .ty-icon:before {
        content: "";
      }
      #AIlogin {
        display: none;
        height: 100%;
        background: rgba(240, 240, 250, 0.8);
        padding: 20px;
        text-align: center;
        border-radius: 8px;
        position: relative;
        top: -500px;
        transition: all 0.3s;
      }
      #AIlogin tr td:first-child {
        text-align: right;
        width: 40%;
      }
      #AIlogin span {
        padding: 8px 20px;
        margin: 0 20px;
        background: #ddd;
        border-radius: 6px;
        font-weight: bold;
      }
      .modal-login .modal-content {
        display: none;
      }
      .modal-login #AIlogin {
        display: block;
      }
      #AIlogin tr {
        border: none;
        background: none;
        display: none;
      }
      #AIlogin td {
        border: none;
        padding: 5px 2px;
      }
      #AIlogin span:hover {
        background: aqua;
        cursor: pointer;
      }
      #AIlogin input {
        border: 1px solid #ddd;
        border-radius: 4px;
      }
      div#AIlogin.login-login {
        top: 1px;
      }
      div#AIlogin.login-reg {
        top: 30px;
      }
      div#AIlogin.login-pws {
        top: 12px;
      }
      #common-dialog .modal-dialog {
        margin-top: 80px;
      }
      .modal-login {
        display: block !important;
        background: rgba(0, 0, 0, 0.2);
      }
      #aiVer::before {
        content: "Version: ";
      }
      #AIlogin.login-login span.log {
        background: aqua;
      }
      #AIlogin.login-reg span.reg {
        background: aqua;
      }
      #AIlogin.login-pws span.pws {
        background: aqua;
      }
      #AIlogin.login-login .btn:before {
        content: "Login";
      }
      #AIlogin.login-reg .btn:before {
        content: "Register";
      }
      #AIlogin.login-pws .btn:before {
        content: "Reset";
      }
      #AIlogin.login-login .login-login,
      #AIlogin.login-pws .login-pws,
      #AIlogin.login-reg .login-reg {
        display: inherit;
      }
      #send {
        bottom: 156px;
        right: 2%;
        position: fixed;
        border-radius: 6px;
        border: none;
        width: 80px;
        height: 30px;
        font: bold 20px/20px Consolas;
        padding: 5px 10px;
        background: #4d7;
        opacity: 0.6;
      }
    </style>
  </head>
  <body style="padding: 0; margin: 0">
    <div id="record"></div>
    <textarea id="aiarea" cols="60" rows="1" placeholder="Ask ChatGPT (Enter: newline, Ctrl+Enter: send)"></textarea>
    <button class="chatbtn">New Chat</button>
    <button class="chatbtn" style="left: 120px">Next Acnt</button>
    <button id="send">Send</button>
  </body>
  <script>
    let drag = 10;
    let cliHei = document.documentElement.clientHeight - 210;
    function scrollToEnd() {
      // 距离顶部的距离
      window.scrollTo(0, aiRecord.offsetHeight - cliHei);
    }
    var AItoken = new Set([
      // 没用了，chatmoss现在会定期刷新token
    ]);
    var AIacnt = [
      // {email:'',password:''},
      { email: "202111200033@mail.bnu.edu.cn", password: "\171\170\71\70\61\63\65\60\131\130\120" },
      { email: "yxphope@qq.com", password: "\171\170\71\70\61\63\65\60\131\130\120" },
      { email: "3240954138@qq.com", password: "\171\170\71\70\61\63\65\60\131\130\120" },
      { email: "2055979171@qq.com", password: "\171\170\71\70\61\63\65\60\131\130\120" },
    ];
    // 下一步:制作侧边栏（功能：搜索、浏览网页、可视化设置、说明、chat、尾注）
    var debugMd = !1;
    if (!window.AIacnt) {
      var AIacnt = [
        // 向此数组中添加账户，当免登录字数用完后，将逐个使用本数组下的账户
        // {email:'',password:''},
      ];
    }
    var curAcnt = -1;
    if (!window.AItoken) {
      // token优先使用
      var AItoken = new Set();
    }
    var curToken = localStorage.token || -1;
    var itToken = AItoken.values();
    var Context = 0; // ChatGPT 上下文数量
    var CTXT = [];
    var tbfigN = 0;
    const Prot = "\x68\x74\x74\x70\x3A\x2F\x2F";
    const ProInt = "\141\160\151\143\156\56\141\151\150\141\157\61\62\63\56\143\156";
    // 思来想去，与其自己做解析，还不如首行写上类型，然后提供一个按钮供用户选择是否粘贴该类型的模板
    /**
     *
     * @return ELement
     */
    function $q(s) {
      return document.querySelector(s);
    }
    var Blur = false;
    var Paste = ($q("#context-menu-for-source") || {}).lastElementChild || undefined;
    /**
     * <p>项目名称: ${project_name} </p>
     * <p>文件名称: ${file_name} </p>
     * <p>描述: [类型描述] </p>
     * <p>创建时间: ${date} </p>
     * <p>公司信息: ************公司 *********部</p>
     * @param string e tagname
     * @param string id
     * @param string cla
     * @param string html
     * @author <a href="mail to: *******@******.com" rel="nofollow">作者</a>
     * @version v1.0
     * @update [序号][日期YYYY-MM-DD] [更改人姓名][变更描述]
     */
    function nE(e, id = undefined, cla = undefined, html = "") {
      var ele = document.createElement(e);
      id && (ele.id = id);
      cla && (ele.className = cla);
      html && (ele.innerHTML = html);
      return ele;
    }
    let ma = nE("div", "tip");
    document.body.appendChild(ma);
    ma.replaceSelection = (s) => {
      ma.innerHTML = s;
      ma.className = "show";
      ma.timeout && clearTimeout(ma.timeout);
      ma.timeout = setTimeout(() => {
        ma.className = "hide";
      }, 3000);
    };
    function show(e) {
      e.style.display = "block";
    }
    function hide(e) {
      e.style.display = "none";
    }

    // 粘贴示例代码，textarea可以多行，input不行
    const Cinput = document.createElement("textarea");
    function copyStr(str, pa = 0) {
      // 不能设置display none，只能脱离文档流、全透明
      Cinput.style.cssText = "opacity:0;position:absolute;z-index:-1;";
      document.body.appendChild(Cinput);
      Cinput.value = str;
      Cinput.select();
      document.execCommand("Copy");
      if (pa) {
        Paste.click();
      }
    }

    function addStyle(css) {
      let c = nE("style");
      c.innerHTML = css;
      document.head.append(c);
    }
    function toOct(str) {
      var octalStr = "";
      for (var i = 0; i < str.length; i++) {
        octalStr += "\\" + str.charCodeAt(i).toString(8);
      }
      return octalStr;
    }
    const urlpart = {
      base: "\x2F\x6C\x75\x6F\x6D\x61\x63\x6F\x64\x65\x2D\x61\x70\x69\x2F\x75\x73\x65\x72\x2F",
      log: "\x6C\x6F\x67\x69\x6E",
      reg: "\x72\x65\x67\x69\x73\x74\x65\x72",
      code: "\x65\x6D\x61\x69\x6C\x43\x6F\x64\x65",
      fgt: "\x66\x6F\x72\x67\x65\x74\x50\x77\x64\x45\x6D\x61\x69\x6C\x43\x6F\x64\x65",
      res: "\x72\x65\x73\x65\x74\x50\x77\x64",
      check: "\57\154\165\157\155\141\143\157\144\145\55\141\160\151\57\141\143\164\151\166\151\164\171\57\163\151\147\156\151\156",
      rem: "\147\145\164\102\141\154\141\156\143\145\111\156\146\157",
      cvs: "\57\154\165\157\155\141\143\157\144\145\55\141\160\151\57\143\157\156\166\145\162\163\141\164\151\157\156",
    };

    var aappii = "\57\141\163\153\57";

    // 程序猿们查到了接口，也不要滥用，否则api提供方ChatMoss倒了，又没得用了。
    var aiIn = $q("#aiarea");
    var aiRecord = $q("#record");
    var newChat = $q(".chatbtn");
    var nextAcnt = newChat.nextElementSibling;
    var sendBtn = nextAcnt.nextElementSibling;
    newChat.addEventListener("click", () => {
      post("cvs", { title: "新建问题", appId: "1" });
    });
    nextAcnt.addEventListener("click", () => {
      curAcnt++;
      post("log", AIacnt[curAcnt]);
    });
    nextAcnt.click();
    var header = {
      Accept: "application/json, text/plain, */*",
      "Content-Type": "application/json",
      "Accept-Language": "en-US",
      // "URL":"http://43.154.117.92/api/chat-process?version=v1.5",
      // "Method":"POST"
      // "token":
    };
    if (localStorage.token) header.token = localStorage.token;
    // 响应结构 {"role":"assistant","id":"chatcmpl-76grWo3IJUipQO7f5oC5BDZVbPzM3","parentMessageId":"a99ae287-841a-4835-af9c-6b33ea5da240","text":"这","delta":"这","detail":{"id":"chatcmpl-76grWo3IJUipQO7f5oC5BDZVbPzM3","object":"chat.completion.chunk","created":1681829086,"model":"gpt-3.5-turbo-0301","choices":[{"delta":{"content":"这"},"index":0,"finish_reason":null}]}}
    // 响应结构 直接是逐字逐字的回应
    var data = { prompt: "Why 1+1 equals to 2", options: { conversationId: "", appId: "1", openaiVersion: "3.5" }, apiKey: "" }; // "conversationId":"MOSS_1684341617931",
    let cvsOpen = false;
    var loginPage = nE(
      "div",
      "AIlogin",
      "login-login",
      `<div style="font: 700 20px sans-serif;"><span class="log">Login</span><span class="reg">Register</span><span class="pws">Reset</span></div><table><tbody><tr class="login-login login-pws login-reg"><td style="width: 40%;">Email</td><td><input type="email"></td></tr><tr id="login-password" class="login-login login-reg"><td>Password</td><td><input type="password"></td><td><svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2148" width="16" height="16" style="cursor: pointer;margin-top: 6px;"><path d="M512 398.336c-75.776 0-137.216 61.44-137.216 137.216s61.44 137.216 137.216 137.216 137.216-61.44 137.216-137.216-61.44-137.216-137.216-137.216z m0 205.824c-37.888 0-68.608-30.72-68.608-68.608s30.72-68.608 68.608-68.608 68.608 30.72 68.608 68.608c0.512 37.376-30.72 68.608-68.608 68.608z m0-369.664c-278.016 0-479.744 179.712-479.744 300.544 0 118.784 215.04 300.544 479.744 300.544 262.144 0 474.624-181.76 474.624-300.544S774.144 234.496 512 234.496z m0 532.992c-237.568 0-411.136-162.816-411.136-232.448 0-79.36 173.568-232.448 411.136-232.448 235.008 0 406.528 162.816 406.528 232.448s-171.52 232.448-406.528 232.448z" p-id="2149"></path></svg></td></tr>
    <tr class="login-reg"><td>Nikename</td><td><input type="text" maxlength="20"></td></tr>
    <tr class="login-reg"><td>Phone</td><td><input type="number" maxlength="11"></td></tr>
    <tr class="login-reg login-pws"><td>Verification</td><td><input type="text" style="width:100px"></td><td style="position:relative;"><span id="login-code" style="    text-align: center;border-radius: 5px;padding: 4px;cursor: pointer;font: 400 14px/1.2 sans-serif;position: absolute;left: -80px;top: 5px;width: 86px;height: 25px;">Send Email</span></td></tr>
    <tr class="login-pws"><td>New Password</td><td><input type="password"></td><td><svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2148" width="16" height="16" style="
    cursor: pointer;margin-top: 6px;
"><path d="M512 398.336c-75.776 0-137.216 61.44-137.216 137.216s61.44 137.216 137.216 137.216 137.216-61.44 137.216-137.216-61.44-137.216-137.216-137.216z m0 205.824c-37.888 0-68.608-30.72-68.608-68.608s30.72-68.608 68.608-68.608 68.608 30.72 68.608 68.608c0.512 37.376-30.72 68.608-68.608 68.608z m0-369.664c-278.016 0-479.744 179.712-479.744 300.544 0 118.784 215.04 300.544 479.744 300.544 262.144 0 474.624-181.76 474.624-300.544S774.144 234.496 512 234.496z m0 532.992c-237.568 0-411.136-162.816-411.136-232.448 0-79.36 173.568-232.448 411.136-232.448 235.008 0 406.528 162.816 406.528 232.448s-171.52 232.448-406.528 232.448z" p-id="2149"></path></svg></td></tr></tbody></table><div><span class="btn" style="float:none;"></span><span>Cancel</span></div>`
    );
    var loginInput = loginPage.querySelectorAll("input");
    var loginMode = loginPage.firstElementChild.children;
    loginMode[0].addEventListener("click", () => {
      loginPage.className = "login-login";
    });
    loginMode[1].addEventListener("click", () => {
      loginPage.className = "login-reg";
    });
    loginMode[2].addEventListener("click", () => {
      loginPage.className = "login-pws";
    });
    var ml = "\x32\x30\x35\x35\x39\x37\x39\x31\x37\x31\x40\x71\x71\x2E\x63\x6F\x6D";
    var svg = loginPage.querySelectorAll("svg");
    for (var i = 0; i < svg.length; i++) {
      svg[i].addEventListener("click", function () {
        var p = this.parentNode.previousSibling.firstChild;
        p.type = p.type === "text" ? "password" : "text";
      });
    }
    var spanBtn = loginPage.lastElementChild.children;
    spanBtn[0].addEventListener("click", () => {
      var data = {};
      if (loginPage.className === "login-login") {
        data = { email: loginInput[0].value, password: loginInput[1].value };
        post("log", data);
      } else if (loginPage.className === "login-reg") {
        data = { email: loginInput[0].value, password: loginInput[1].value, nickname: loginInput[2].value, emailCode: loginInput[4].value, phone: loginInput[3].value, invite: ml };
        post("reg", data);
      } else if (loginPage.className === "login-pws") {
        data = { email: loginInput[0].value, emailCode: loginInput[4].value, password: loginInput[5].value };
        post("res", data);
      }
      var y = loginPage.getBoundingClientRect().y;
      hide(modal);
      modal.classList.remove("modal-login");
      if (y > 40) {
        show(modal);
      }
    });
    spanBtn[1].addEventListener("click", () => {
      var y = loginPage.getBoundingClientRect().y;
      modal.classList.remove("modal-login");
      loginPage.className = "";
      if (y > 40) {
        show(modal);
      }
    });
    var logCode = loginPage.querySelector("#login-code");
    logCode.addEventListener("click", () => {
      if (logCode.disabled) {
        ma && ma.replaceSelection("Please wait a minute and try again");
        return;
      }
      logCode.disabled = true;
      if (loginPage.className === "login-reg") {
        post("code", { email: loginInput[0].value, password: loginInput[1].value, nickname: loginInput[2].value });
      } else {
        post("fgt", { email: loginInput[0].value });
      }
      logCode.style.backgroundColor = "#999";
      setTimeout(() => {
        logCode.disabled = false;
        logCode.style.backgroundColor = "#2ba245";
      }, 55000);
    });
    /* var localToken = (localStorage.getItem("AItoken") || "").split(","); // token 会更新，不能用了
  if (localToken) {
    // 每个token都特长，超过两百个字符，但长度并不固定
    localToken.forEach((e) => {
      if (e.length > 150) {
        AItoken.add(e);
      }
    });
  } */
    sendBtn.addEventListener("click", send);
    function send() {
      console.log(aiIn.value);
      aiRecord.appendChild(nE("div", 0, "record", aiIn.value.replaceAll("\n", "<br>")));
      let ans = nE("pre", 0, "record");
      ans.style.backgroundColor = "#0ff5";
      aiRecord.appendChild(ans);
      scrollToEnd();
      var xhr = new XMLHttpRequest();
      xhr.open("POST", getUrl()); // "http://localhost:8030");
      for (key in header) {
        xhr.setRequestHeader(key, header[key]);
      }
      // xhr.setRequestHeader('Header',JSON.stringify(header));
      var len = 0;
      xhr.onprogress = () => {
        // var r = JSON.parse(xhr.responseText.slice(len)); // 效率感觉不如查找替换和正则
        var res = xhr.responseText;
        // var ct = res.slice(len);
        // len = res.length;
        // eval('ct="' + text.slice(pre) + '";'); // = text.slice(pre).replace(/\\n/g, "\n").replace(/\\\n/g, "\\n").replace(/\\\\/g, "\\").replace(/\\"/g, '"');
        ans.innerText = res;
        scrollToEnd();
      };
      xhr.onload = () => {
        var res = xhr.responseText;
        var ct = res.slice(len);
        if (res.slice(0, 9) === '{"msg": "') {
          eval("ct='" + res + "';");
          ma && ma.replaceSelection("\nError: " + ct + "\n");
          if (Context) {
            CTXT.pop();
          }
          if (curToken < AItoken.size - 1) {
            // 不能同时copy太多，会堵塞，最后复制的是同一个
            setTimeout(() => {
              curToken++;
              header["token"] = itToken.next().value;
              ma && ma.replaceSelection("\nNext token used, remains " + (AItoken.size - curToken).toString() + "\n");
            }, 400);
          } else if (curAcnt < AIacnt.length - 1) {
            curAcnt++;
            console.log(curAcnt, AIacnt);
            post("log", AIacnt[curAcnt]);
          } else {
            // 设计登录页面
            loginPage.className = "login-login";
            modal.classList.add("modal-login");
          }
        }
      };
      if (Context) {
        if (CTXT.length > Context - 2) {
          // 头部移除两个，便于存放回答，保证双数
          CTXT.shift();
          CTXT.shift();
        }
        CTXT.push(aiIn.value);
        data.prompt = CTXT.join("\n");
      } else {
        data.prompt = aiIn.value;
      }
      xhr.send(JSON.stringify(data));
      aiIn.value = "";
      return false;
    }
    aiIn.prompt = [];
    aiIn.ind = 0;
    aiIn.addEventListener("keydown", (e) => {
      var row = aiIn.value.split("\n").length;
      if (e.key === "Enter" && !e.ctrlKey) {
        row++;
      }
      aiIn.rows = row > 5 ? 5 : row;
      if (header.token && !cvsOpen) {
        post("cvs", { title: "新建问题", appId: "1" });
        cvsOpen = true;
      }
      if (e.ctrlKey) {
        if (e.key === "Enter") {
          aiIn.prompt.push(aiIn.value);
          aiIn.ind = aiIn.prompt.length;
          send(e);
        } else if (e.key === "ArrowUp") {
          if (aiIn.ind > 0) {
            aiIn.ind--;
            aiIn.value = aiIn.prompt[aiIn.ind];
          }
        } else if (e.key === "ArrowDown") {
          if (aiIn.ind < aiIn.prompt.length - 1) {
            aiIn.ind++;
            aiIn.value = aiIn.prompt[aiIn.ind];
          }
        }
      }
    });
    var getUrl = () => {
      var url = Prot + ProInt;
      return url + aappii;
    };
    var ai = nE(
      "span",
      "AIbtn",
      "btn toolbar-icon mybtn btnlist",
      `<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9229" width="15" height="15"><path d="M196.1 989.7c-9.1 0-17.6-3.5-24-9.9-6.3-6.3-9.9-15-9.9-24v-236c0-1.9-1.4-3.5-3.3-3.8-39.1-5.1-108.4-19.7-133.7-60.7-12.4-20.1-13.5-44.2-3.1-67.7 27.2-61.2 72.5-105.4 97-126.2 0.7-0.6 1.2-1.5 1.3-2.4 8.9-71.3 71.3-426.8 428.7-426.8 194.6 0 351.9 88.1 420.8 235.5 73.4 157.3 30.3 352.4-118.3 535.4-0.6 0.7-0.8 1.5-0.8 2.4V950c0 18.7-15.2 33.9-33.9 33.9S783 968.7 783 950V791.8c0-8 2.8-15.7 7.9-21.8C929.1 604.9 972 432.1 908.6 296.2c-57.5-123-191.8-196.4-359.4-196.4-336.2 0-361.8 364.6-362.8 380.1-0.7 10.1-5.7 19.4-13.9 25.4-6.3 4.8-60.7 47.3-88.4 109.7-0.4 1-0.4 2.1 0 3 7.1 16.8 65.6 31.1 113.6 33.5 18.1 0.9 32.2 15.7 32.3 33.8V918c0 2.1 1.7 3.8 3.8 3.8h189.3c18.7 0 33.9 15.2 33.9 33.9s-15.2 33.9-33.9 33.9h-227z" fill="#333333" p-id="9230"></path><path d="M583.9 687.3c-14.3 0-27.1-9-31.9-22.4l-21.3-62.3c-0.5-1.5-2-2.6-3.6-2.6H415.2c-1.6 0-3.1 1-3.6 2.5L389 665.4c-5.1 12.8-17.5 21.1-31.4 21.1-3.9 0-7.8-0.7-11.5-2-17.2-6.2-26.4-24.7-20.8-42.2l116.3-323.6c4.8-13.4 17.6-22.4 31.9-22.4 14.6 0.1 27.4 9.3 32 22.9l110.7 323.7c5.7 17.4-3.9 36.6-21.3 42.5-3.6 1.3-7.2 1.9-11 1.9z m-111.4-247c-1.6 0-3.1 1-3.6 2.5L438.7 527c-0.4 1.2-0.2 2.5 0.5 3.5s1.9 1.6 3.1 1.6h59c1.2 0 2.4-0.6 3.1-1.6 0.7-1 0.9-2.3 0.5-3.5l-28.8-84.2c-0.5-1.5-1.9-2.5-3.6-2.5z m225 244.5c-18.7 0-33.9-14.7-33.9-32.7V329.3c0-18 15.2-32.7 33.9-32.7s33.9 14.7 33.9 32.7v322.9c-0.1 18-15.3 32.6-33.9 32.6z" fill="#333333" p-id="9231"></path></svg><div style="position: absolute;height: 100%;width: 43px;left: -1px;top: 0;z-index: -1;"></div>`
    );
    ai.title = "Chat with AI";
    ai.style.cssText = "position: relative;";
    var openLogin = nE(
      "div",
      "openLogin",
      "export-choice",
      `<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="12" height="12"><path d="M575.215 547.318c53.367-24.316 90.562-78.011 90.562-140.522 0-85.257-69.149-154.383-154.406-154.383-85.299 0-154.427 69.126-154.427 154.383 0 62.49 37.172 116.185 90.562 140.522-87.156 27.24-150.586 108.698-150.586 204.715 0 12.071 9.779 21.827 21.827 21.827s21.827-9.756 21.827-21.827c0-94.161 76.613-170.774 170.776-170.774 94.184 0 170.797 76.613 170.797 170.774 0 12.071 9.756 21.827 21.827 21.827 12.07 0 21.827-9.756 21.827-21.827 0.021-95.994-63.43-177.475-150.586-204.715zM400.621 406.817c0-61.072 49.678-110.729 110.773-110.729 61.072 0 110.75 49.657 110.75 110.729 0 61.094-49.678 110.794-110.75 110.794-61.095 0-110.773-49.7-110.773-110.794z" p-id="2665"></path><path d="M511.371 960.81c-246.951 0-447.869-200.918-447.869-447.891 0-246.93 200.919-447.871 447.869-447.871 246.973 0 447.892 200.919 447.892 447.871 0 246.973-200.919 447.891-447.892 447.891z m0-854.269c-224.098 0-406.398 182.301-406.398 406.377s182.3 406.397 406.398 406.397c224.099 0 406.42-182.321 406.42-406.397S735.47 106.541 511.371 106.541z" p-id="2666"></path></svg> Login`
    );
    openLogin.style.width = "120px";
    openLogin.style.overflow = "hidden";
    openLogin.title = "Log on to ChatGPT";
    var ctxtON = nE(
      "div",
      "ctxt",
      "export-choice",
      `<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" width="12" height="12"><path d="M851.672 273.064H749.472V170.44C749.472 76.336 673.056 0 579.136 0h-408.8C76.416 0 0 76.336 0 170.44v546.136c0 32.92 41.832 46.512 61.32 20.48l132.936-177.6a33.632 33.632 0 0 1 27.176-13.552h51.104v102.4c0 94.112 76.416 170.664 170.336 170.664h357.696c10.824 0 20.736 4.944 27.184 13.56l132.936 177.6c19.616 26.208 61.32 12.256 61.32-20.48V443.496c0-94.104-76.416-170.44-170.336-170.44zM272.536 443.504v34.36h-51.104c-32 0-62.536 15.048-81.68 40.64L68.136 614.176V170.44c0-56.464 45.84-102.4 102.2-102.4h408.8c56.352 0 102.2 45.936 102.2 102.4v102.632H442.872c-93.92 0-170.336 76.328-170.336 170.432z m681.336 443.736l-71.616-95.672c-19.152-25.584-49.68-40.64-81.68-40.64H442.864c-56.36 0-102.2-46.16-102.2-102.624v-204.8c0-56.464 45.84-102.4 102.2-102.4h408.8c56.352 0 102.2 45.936 102.2 102.4v443.736z m-442.872-307.2a34.104 34.104 0 0 0 34.072-34.136 34.104 34.104 0 0 0-34.072-34.136 34.104 34.104 0 0 0-34.064 34.136 34.104 34.104 0 0 0 34.064 34.136z m136.272 0a34.104 34.104 0 0 0 34.064-34.136 34.104 34.104 0 0 0-34.064-34.136 34.104 34.104 0 0 0-34.072 34.136 34.104 34.104 0 0 0 34.072 34.136z m136.264 0a34.104 34.104 0 0 0 34.064-34.136 34.104 34.104 0 0 0-34.064-34.136 34.104 34.104 0 0 0-34.064 34.136 34.104 34.104 0 0 0 34.064 34.136z" fill="#515151" p-id="2689"></path></svg> Context: <input type="number" min="0" max="50" style="width: 32px;padding: 0;border: none;">`
    );
    var aiVer = nE("div", "aiVer", "export-choice", "3.5");
    ctxtON.style.width = "120px";
    aiVer.style.cssText = "width:120px;";
    var ctxtIN = ctxtON.querySelector("input");
    ctxtIN.value = Context;
    var residue = nE("div", "aiRes", "export-choice");
    residue.style.width = "120px";
    ai.appendChild(openLogin);
    ai.appendChild(ctxtON);
    ai.appendChild(aiVer);
    ai.appendChild(residue);
    openLogin.onclick = () => {
      loginPage.className = "login-login";
      modal.classList.add("modal-login");
    };
    ctxtIN.onchange = () => {
      Context = parseInt(ctxtIN.value);
    };
    ctxtON.onclick = () => {
      if (ctxtIN.value >= 30) {
        ctxtIN.value = Context = 0;
      } else {
        ctxtIN.value = Context = 30;
      }
    };
    aiVer.onclick = () => {
      let s = aiVer.innerHTML;
      s = s === "3.5" ? "3.5-16k" : s === "3.5-16k" ? "4.0" : "3.5";
      aiVer.innerHTML = s;
      data.options.openaiVersion = s;
    };
    function post(mod, dat) {
      if (!urlpart[mod]) {
        return;
      }
      var xhr = new XMLHttpRequest();
      var url = Prot + ProInt;
      mod !== "check" && mod !== "cvs" && (url += urlpart.base);
      url += urlpart[mod];
      xhr.open(mod !== "rem" ? "POST" : "GET", url);
      xhr.setRequestHeader("Content-Type", "application/json");
      (mod === "check" || mod === "rem" || mod === "cvs") && xhr.setRequestHeader("token", header["token"]);
      xhr.onload = () => {
        if (xhr.responseText.indexOf('"msg":"success') > 0) {
          if (mod === "log") {
            openLogin.innerHTML = dat.email;
            header.token = xhr.responseText.slice(xhr.responseText.indexOf('Token":"') + 8, xhr.responseText.lastIndexOf('"}'));
            localStorage.token = header.token;
            AItoken.add(header["token"]);
            var s = "";
            AItoken.forEach((e) => (s += e + ","));
            s = s.slice(0, -1);
            localStorage.setItem("AItoken", s);
            var s = dat instanceof Object ? dat.email : "";
            ma && ma.replaceSelection("\nLogged in\n" + s);
            post("check", {});
            post("rem");
          } else if (mod === "reg") {
            ma && ma.replaceSelection("\nRegistered. Please keep your account and password safe.");
            var dt = { email: dat.email, password: dat.password };
            post("log", dt);
          } else if (mod === "res") {
            ma && ma.replaceSelection("\nReset successfully.");
            post("log", { email: dat.email, password: dat.password });
          } else if (mod === "fgt") {
            ma && ma.replaceSelection("\nSent");
          } else if (mod === "code") {
            ma && ma.replaceSelection("\nSent.");
          } else if (mod === "check") {
            // ma && ma.replaceSelection("\nCheck Successfully.");
          } else if (mod === "rem") {
            // ma && ma.replaceSelection("\n" + xhr.responseText);
            let r = JSON.parse(xhr.responseText);
            residue.innerHTML = r.data.residueCountFree / 1000;
          }
        } else if (mod === "cvs") {
          let s = xhr.responseText.indexOf('"id":"') + 6;
          if (xhr.responseText.indexOf('code":0') < 0 || s < 0) {
            ma.replaceSelection("Failed to Open Conversation.");
            cvsOpen = false;
            return;
          }
          let e = xhr.responseText.indexOf('"', s);
          data.options.conversationId = s = xhr.responseText.slice(s, e);
          ma.replaceSelection(`Conversation Opened (id:${s})`);
          console.log(s, xhr.responseText);
        } else if (mod === "check") {
          // ma && ma.replaceSelection("\nAlready Checked Today.");
        } else {
          alert("Failed!\n" + xhr.responseText);
        }
      };
      if (!dat) {
        xhr.send();
        return;
      }
      if (dat instanceof Object) {
        dat = JSON.stringify(dat);
      }
      xhr.send(dat);
      dat = JSON.parse(dat);
    }
    var curUser;
  </script>
</html>
